package com.example.hm_dtfkz.ui.dialog;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.WindowManager;

import com.android.base.util.ActivityClickUtil;
import com.android.base.util.DisplayUtil;
import com.dq.ad.AdManager;
import com.example.hm_dtfkz.R;
import com.example.hm_dtfkz.config.AppConfig;
import com.example.hm_dtfkz.databinding.DialogWithdrawalSuccessBinding;
import com.example.hm_dtfkz.util.AnimUtil;

/**
 * 去提现
 * <p>
 * Author: admin
 * Date: 2021/11/16 16:05
 * Description:
 */
public class DialogWithdrawalSuccess extends Dialog implements View.OnClickListener {

    private DialogWithdrawalSuccessBinding withdrawalSuccessBinding;
    private OnClickLister clickLister;
    private final Activity activity;
    private boolean isQueue;
    private double cash = 0.0; //现金

    public DialogWithdrawalSuccess(Activity a) {
        super(a, R.style.dialog_loading);
        this.activity = a;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        withdrawalSuccessBinding = DialogWithdrawalSuccessBinding.inflate(getLayoutInflater());
        setContentView(withdrawalSuccessBinding.getRoot());

        getWindow().getDecorView().setPadding(0, 0, 0, 0);
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = DisplayUtil.getScreenWidth(activity);
        lp.height = DisplayUtil.getScreenHeight(activity);
        getWindow().setAttributes(lp);

        setCancelable(false);
        setCanceledOnTouchOutside(false);
        initView();
        initLister();
    }

    @SuppressLint("SetTextI18n")
    private void initView() {
        ActivityClickUtil.getInstance().clear();
        AnimUtil.receiveAnim(activity, withdrawalSuccessBinding.imgReceive);

        String title;
        String content1;
        String tips;
        if (isQueue) {
            title = "<font color='#FD001A'>" + cash + "</font>元提现请求已提交";
            content1 = "当前时段提现人数过多，奖励排队审核中";
            tips = "对此结果有疑问请添加客服QQ群：" + AppConfig.QQ_GROUP;
//            withdrawalSuccessBinding.label2.setVisibility(View.VISIBLE);
            withdrawalSuccessBinding.label3.setVisibility(View.VISIBLE);
        } else {
            title = "成功提现<font color='#FD001A'>" + cash + "</font>元";
            content1 = "预计今日还可提现<font color='#FD001A'>" + AppConfig.getRemainWithdrawalTimes() + "</font>次";
            tips = "赚取更多现金请加官方网赚QQ群：" + AppConfig.QQ_GROUP;
//            withdrawalSuccessBinding.label2.setVisibility(View.INVISIBLE);
            withdrawalSuccessBinding.label3.setVisibility(View.INVISIBLE);
        }
        withdrawalSuccessBinding.tvTitle.setText(Html.fromHtml(title));
        withdrawalSuccessBinding.label1.setText(Html.fromHtml(content1));
        withdrawalSuccessBinding.tvQqTips.setText(tips);

        AdManager.getInstance().showNativeAD(activity, withdrawalSuccessBinding.layoutBanner, DisplayUtil.getScreenWidthDp(activity) - 48, 0, AdManager.NATIVE_AD_TYPE_UP_IMAGE, false, new AdManager.OnNativeVideoADListener() {
            @Override
            public void onSuccess() {
                withdrawalSuccessBinding.layoutBanner.setBackgroundColor(activity.getResources().getColor(R.color.Color_FFFFFF));
            }

            @Override
            public void onClosed() {
                withdrawalSuccessBinding.layoutBanner.setBackgroundColor(activity.getResources().getColor(android.R.color.transparent));
            }

            @Override
            public void onError() {
            }

            @Override
            public void onClick() {
            }

            @Override
            public void onShow(View view) {

            }
        });
    }

    private void initLister() {
        withdrawalSuccessBinding.imgReceive.setOnClickListener(this);
        withdrawalSuccessBinding.imgClose.setOnClickListener(this);
    }

    public DialogWithdrawalSuccess setClickLister(OnClickLister lister) {
        this.clickLister = lister;
        return this;
    }

    public DialogWithdrawalSuccess setQueue(boolean queue) {
        this.isQueue = queue;
        return this;
    }

    public DialogWithdrawalSuccess setCash(double cash) {
        this.cash = cash;
        return this;
    }

    @Override
    public void onClick(View v) {
        if (ActivityClickUtil.getInstance().isFastClick()) {
            //防止用户快速点击
            return;
        }
        dismiss();
        if (v.getId() == R.id.imgReceive) {
            AdManager.getInstance().showInterstitialAD(activity);
            if (this.clickLister != null) {
                this.clickLister.onWithdrawal();
            }
        }
    }

    public interface OnClickLister {
        void onWithdrawal();
    }
}